package org.liky.game.frame;
import java.awt.*;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;
import javax.swing.JFrame;
import javax.swing.JOptionPane;

public class MyChessFrame extends JFrame implements MouseListener {
    public MyChessFrame() {
        this.setTitle("五子棋益智游戏");       //设置窗体标题
        this.setSize(700, 500);  //设置窗体大小
        this.setResizable(false);           //设置窗体大小不可变
        this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);  //设置窗体关闭方式，关闭窗体时同时结束程序
        int width = Toolkit.getDefaultToolkit().getScreenSize().width;
        int height = Toolkit.getDefaultToolkit().getScreenSize().height;
        /**   System.out.println("宽度为：" + width);
              System.out.println("高度为：" + height);    **/
        this.setLocation((width - 100) / 2, (height - 500) / 2);   //设置窗口初始显示位置在屏幕正中央

        this.addMouseListener(this);

        this.setVisible(true);               //设置窗体可见
    }


    public void paint(Graphics g){
        /**
        g.drawString("五子棋游戏",20,40);   //drawString绘制字符串
        g.drawOval(20,40,40,40); //drawOval绘制一个空心圆形
        g.fillOval(20,40,20,20); //fillOval绘制一个实心圆形
        g.drawLine(20,40,40,20);
         **/
        BufferedImage image = null;
        try{
            image = ImageIO.read(new File("C:/Users/16399/Pictures/Screenshots/屏幕截图 2024-12-21 165809.png"));
        }catch(IOException e){
            e.printStackTrace();
        }
        g.drawImage(image,0,0,this);   //drawImage绘制已经存在的图片，将一个图片直接显示在窗体中
        g.setFont(new Font("黑体",40,40)); //设置绘制文字的字体
        g.drawString("欢迎使用五子棋游戏！",20,100);   //drawString绘制字符串

    }



    @Override
    public void mousePressed(MouseEvent e) {
        //mousePressed鼠标按下
        System.out.println("点击位置：X-->"+e.getX());  //getX得到鼠标横向位置坐标
        System.out.println("点击位置：Y-->"+e.getY());  //getY得到鼠标纵向位置坐标
    }


    @Override
    public void mouseClicked(MouseEvent e) {
        //鼠标点击
    }

    @Override
    public void mouseReleased(MouseEvent e) {
        //鼠标抬起
    }

    @Override
    public void mouseEntered(MouseEvent e) {
        //鼠标进入
    }

    @Override
    public void mouseExited(MouseEvent e) {
        //鼠标离开
    }

}
